package cn.cheln.support.ui.adapter;

import android.database.Cursor;
import cn.cheln.support.log.Logs;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;

public class ItemDataSrc
{
  public static final int CURSOR_TYPE = 0;
  public static final int LIST_OBJECT_TYPE = 1;
  private List list;
  protected Cursor mCurrentCursor;
  protected int mCursorGetCount;
  private Map<String, Class> nameTypePair;
  List<Integer> posKeys;
  Map<Integer, Cursor> tailIdx_Cursor_Map = new TreeMap(new Comparator()
  {
    public int compare(Integer paramInteger1, Integer paramInteger2)
    {
      return (paramInteger1.intValue() - paramInteger2.intValue());
    }
  });
  private int type = -1;

  public ItemDataSrc()
  {
  }

  public ItemDataSrc(Cursor paramCursor, Map<String, Class> paramMap)
  {
    this.tailIdx_Cursor_Map.put(Integer.valueOf(-1 + paramCursor.getCount()), paramCursor);
    Logs.i("put " + (-1 + paramCursor.getCount()) + " " + paramCursor + " " + paramCursor.getCount());
    setDataSrc(paramCursor, paramMap);
    this.mCursorGetCount += paramCursor.getCount();
  }

  public ItemDataSrc(List paramList)
  {
    setContent(paramList);
  }

  public ItemDataSrc(Map<String, Class> paramMap)
  {
    this.type = 0;
    this.nameTypePair = paramMap;
  }

  public void clear()
  {
    if (this.type == 0)
    {
      this.mCurrentCursor = null;
      this.tailIdx_Cursor_Map.clear();
    }
    do
      return;
    while (this.type != 1);
    this.list.clear();
  }

  public Object getContent()
  {
    switch (this.type)
    {
    default:
      return null;
    case 0:
      return this.mCurrentCursor;
    case 1:
    }
    return this.list;
  }

  public int getCount()
  {
    switch (this.type)
    {
    default:
    case 0:
      while (true)
      {
        return 0;
        if (this.mCurrentCursor != null)
          return this.mCursorGetCount;
      }
    case 1:
    }
    return this.list.size();
  }

  public Object getItem(int paramInt)
  {
    switch (this.type)
    {
    default:
    case 0:
      int i;
      Cursor localCursor;
      int k;
      int l;
      do
      {
        return null;
        if (this.posKeys == null)
          this.posKeys = new ArrayList(this.tailIdx_Cursor_Map.keySet());
        i = Collections.binarySearch(this.posKeys, Integer.valueOf(paramInt));
        if (i < 0)
          i = -1 + -i;
        int j = this.posKeys.size();
        localCursor = null;
        if (i >= j)
          break label198;
        k = ((Integer)this.posKeys.get(i)).intValue();
        localCursor = (Cursor)this.tailIdx_Cursor_Map.get(Integer.valueOf(k));
        l = localCursor.getCount();
      }
      while (l == 0);
      if (i == 0);
      for (int i1 = paramInt; (localCursor != null) && (localCursor.isClosed()); i1 = l - 1 - (k - paramInt))
        return localCursor;
      localCursor.moveToPosition(i1);
      label198: return localCursor;
    case 1:
    }
    if (paramInt < this.list.size());
    for (Object localObject = this.list.get(paramInt); ; localObject = null)
      return localObject;
  }

  public Map<String, Class> getNameTypePair()
  {
    return this.nameTypePair;
  }

  public int getType()
  {
    return this.type;
  }

  public void removeCursor(Cursor paramCursor)
  {
    Iterator localIterator = this.tailIdx_Cursor_Map.entrySet().iterator();
    boolean bool = localIterator.hasNext();
    Object localObject = null;
    if (!(bool));
    while (localObject == null)
    {
      return;
      Map.Entry localEntry = (Map.Entry)localIterator.next();
      if (localEntry.getValue() == paramCursor);
      localObject = localEntry.getKey();
    }
    this.tailIdx_Cursor_Map.remove(localObject);
    this.mCursorGetCount -= paramCursor.getCount();
  }

  public void setContent(List paramList)
  {
    if (paramList == null)
      throw new NullPointerException("list is null");
    this.list = paramList;
    this.type = 1;
  }

  public void setDataSrc(Cursor paramCursor, Map<String, Class> paramMap)
  {
    if (paramCursor == null)
      throw new NullPointerException("cursor is null");
    this.mCurrentCursor = paramCursor;
    this.type = 0;
    this.nameTypePair = paramMap;
  }

  public void swapCursor(Cursor paramCursor)
  {
    setDataSrc(paramCursor, this.nameTypePair);
    if (paramCursor.getCount() == 0);
    for (int i = -1; ; i = ((Integer)this.tailIdx_Cursor_Map.keySet().toArray()[(-1 + this.tailIdx_Cursor_Map.size())]).intValue() + paramCursor.getCount())
    {
      Integer localInteger = Integer.valueOf(i);
      this.tailIdx_Cursor_Map.put(localInteger, paramCursor);
      this.mCursorGetCount += paramCursor.getCount();
      return;
    }
  }
}

/* Location:           H:\360云盘\lewa_explorer_3.0\bin\FileApp_orig_dex2jar.jar
 * Qualified Name:     cn.cheln.support.ui.adapter.ItemDataSrc
 * JD-Core Version:    0.5.2
 */